import RookieOverView from '../../common/RookieOverView';
import PauseView from '../../common/PauseView';
export default class QuickTool {
    static winsc = cc.winSize
    
    public static randomNum(min:number, max:number) : number{
        return Math.floor(Math.random()*(max-min+1)+min);
    }

    public static getRandomInt(min, max) : number {
        return Math.floor(Math.random() * (max - min)) + min;
    }
	
    public static randomDecimal(min:number, max:number) : number{
        return Math.random()*(max-min+1)+min;
    }



    public static loadSprite(sprite : cc.Sprite, path : string, callback: any = null){
        if (sprite == null) return
        if (!path) return

        cc.loader.loadRes(path, cc.SpriteFrame, (err, spr : cc.SpriteFrame)=>{
            if (err){
                return console.log(err)
            }
            sprite.spriteFrame = spr
            if (callback != null) {
                callback()
            }
        })
    }

    public static addZero (n: number, count: number): string {
        let str = n.toString()
        if (str.length < count) {
            for (let i=0;i<count-str.length;i++) {
                str = "0" + str
            }
        }

        return str
    }

    public static safeCall1(obj, param=null) : any{
		if (!QuickTool.isNullToo(obj)){
			return obj(param)
		}
		return null
    }
    
    public static notNullToo(data) : boolean{
        if (data == null || data == undefined){
            return false
        }

        return true
	}

    public static isNullToo(data) : boolean{
        if (data == null || data == undefined){
            return true
        }

        return false
    }
    






/////////特有
    public static selectAnimate (node: cc.Node) {
        node.runAction(cc.repeatForever(cc.sequence([
            cc.scaleTo(0.3,1.1),
            cc.scaleTo(0.3,0.9),
        ])))
    }

    public static loadRookieOver (complete: (view:RookieOverView)=>void) {
        cc.loader.loadRes("prefab/common/RookieOver", cc.Prefab, (err, prefab)=>{
            let node = cc.instantiate(prefab) as cc.Node
            complete(node.getComponent(RookieOverView))
        })
    }

    public static loadRookiePause (complete: (view:PauseView)=>void) {
        cc.loader.loadRes("prefab/common/PauseView", cc.Prefab, (err, prefab)=>{
            let node = cc.instantiate(prefab) as cc.Node
            complete(node.getComponent(PauseView))
        })
    }

    public static loadOver (win:boolean, complete: (view:cc.Node)=>void) {
        cc.loader.loadRes("prefab/common/over", cc.Prefab, (err, prefab)=>{
            let node = cc.instantiate(prefab) as cc.Node
            node.getChildByName("correct").active = win
            node.getChildByName("wrong").active = !win

            node.name="overnode"

            let anim = node.getChildByName("wrong")
            if (win) {
                anim = node.getChildByName("correct")
            }

            anim.scale = 0.3
            anim.runAction(cc.sequence([
                cc.scaleTo(0.3, 2.0),
                cc.scaleTo(0.2,1.0)
            ]))

            complete(node)
        })
    }
}

/**
 * public void NOSomethingA()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingB()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingC()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingD()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingE()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingF()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingG()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingH()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingI()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingJ()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingK()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingL()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingM()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingN()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingO()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingP()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingQ()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingR()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingS()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingT()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingU()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
public void NOSomethingV()
{
    string name = "NoName";
    string first = "what monther's is who?011245";
}
 */